import pymysql

try:
    connection = pymysql.connect(
        host="192.168.21.130",
        port=3306,
        user="python",
        passwd="python",
        db="python",
        charset="utf8")
    cursor_test = connection.cursor()
    input_name=input("请输入您要添加的学生姓名：")
    # 插入语句
    sql="insert into students(name) values(%s)"
    cursor_test.execute(sql,input_name)
    connection.commit()

    cursor_test.close()
    connection.close()
    print("OK")
except Exception as result:
    print("异常信息为：%s"%result)